<?php
class Application_Model_DbTable_Campaign extends Zend_Db_Table_Abstract
{
	protected $_name = 'campaign';
	
	public function getAllList()
	{
		$result = array();
	
		$data = $this->fetchAll()->toArray();
	
		foreach ($data as $value)
		{
			$id = $value['id'];
				
			$result[$id] = $value['name'];
		}
	
		return $result;
	}
	
	public function addCampaign($title, $body, $userid)
	{
		$data = array
		(
			'title' => $title,
			'body' => $body,
			'created_user' => $userid,
			'created_time' => time(),
		);
		$this->insert($data);
	}
	
	public function updateCampaign($id, $title, $body)
	{
		$data = array
		(
			'title' => $title,
			'body' => $body,
		);
		$this->update($data, 'id = '. (int)$id);
	}
	
	public function getCampaign($id)
	{
		$result = array();
		
		$id = (int)$id;
		$row = $this->fetchRow('id = ' . $id);
		if ($row) 
		{
			$result = $row->toArray();
		}
		return $result;
	}
	
	public function deleteCampaign($id)
	{
		$this->delete('id =' . (int)$id);
	}
}